package com.alibaba.otter.node.etl.load.loader.mq.producer;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @author zhenglincheng
 * @version 0.0.1
 * @description
 * @date 2021/5/11 10:55
 */
public interface MQProducer {

    /**
     * Init producer.
     *
     * @param mqProperties MQ config
     */
    void init(MQProperties mqProperties);

    /**
     * Send canal message to related topic
     *
     * @param message canal message
     * @throws IOException
     */
    void send(Map<String, Object> message, Callback callback) throws IOException;

    boolean send(Map<String, Object> message) throws IOException;

    /**
     * 单条消息发送
     */
    boolean send(Integer partition, String key, String topic, Map<String, Object> data) throws IOException;

    boolean send(Integer partition, String key, String topic, List<Map<String, Object>> messages, BiConsumer<Integer, Boolean> biConsumer) throws IOException;

    /**
     * Stop MQ producer service
     */
    void stop();

    interface Callback {

        void commit();

        void rollback();
    }
}
